******************************
**** QUANTILE REGRESSION *****
******************************
clear all
set more off

local outcome zGradeConditional
local dataset "/Users/yasenov/Desktop/replication package/master.dta"
local uqrdataset uqreg_est_fe_zcond
local cqrdataset cqreg_est_fe_zcond
local graphname qreg_fe_zcond
local quantile_grid= "0.05 .1 .15 .2 .25 .3 .35 .4 .45 .5 .55 .6 .65 .7 .75 .8 .85 .9 .95"

capture erase `uqrdataset'.dta

***** UQR Regressions ****/
use "`dataset'", clear

foreach tau of numlist `quantile_grid' {
	local Tau = 100 * `tau'
	di "Year = Pooled"
	xi: xtrifreg `outcome' starttime SDstarttime student_fatigue, fe i(student_id_group) quantile(`tau')
		
	preserve
	parmest, fast
	gen quantile=`tau'
	keep if parm == "SDstarttime" | parm == "starttime" 
	capture save `uqrdataset'
	if _rc!=0 append using `uqrdataset'
	save `uqrdataset', replace
	restore
	
	xi: xtrifreg `outcome' starttime IQRstarttime student_fatigue, fe i(student_id_group) quantile(`tau')
	preserve
	parmest, fast
	gen quantile=`tau'
	keep if parm == "IQRstarttime"
	append using `uqrdataset'
	save `uqrdataset', replace
	restore
}


*****************
*****************

clear
use `uqrdataset'

twoway (rarea min max q if parm == "SDstarttime", color(gs14)) ///
	(connected est q if parm == "SDstarttime", yline(0)) , ///
	legend(off) title("Panel A: {&sigma}(Start Time)") xtitle("Quantile") ytitle("Coefficient") ///
	ylabel(-.04(.04).08)
	graph copy four, replace	
	
twoway (rarea min max q if parm == "IQRstarttime", color(gs14)) ///
	(connected est q if parm == "IQRstarttime", yline(0)) , ///
	legend(off) title("Panel B: IQR(Start Time)") xtitle("Quantile") ytitle("Coefficient") ///
	ylabel(-.03(.02).03)
	graph copy five, replace	
	
graph combine four five, imargin(small)	
